page.pageInit = function(){
  //初始化grid
  GirdCtr.gridInit();
  GirdCtr.buttonBind()
}

//grid控制器
var GirdCtr =  $.extend({},defaultGridConFig,{
   gridInit: function(){
	 var _this = this;
	//创建jqGrid组件
	_this.grid = $("#mainGrid").jqGrid({
		 			datatype: "json",
		 			//postData:{parentMenuId:0},
		 			url : contextPath+'/act/deal/queryMyUpcoming.htm',//组件创建完成之后请求数据的url
					datatype : "json",//请求数据返回的类型。可选json,xml,txt
					colModel : [ //jqGrid每一列的配置信息。包括名字，索引，宽度,对齐方式.....
					             {label:"任务ID", name : "taskId",sortable:false,key:true,width : 300},
					             {label:"流程实例ID", name : 'instanceId',sortable:false,hidden:true,width : 200,align : "center"}, 
					             {label:"流程定义ID", name : 'defId',sortable:false,hidden:true,width : 200,align : "center"}, 
					             {label:"actKey", name : 'actKey',sortable:false,hidden:true,width : 200,align : "center"}, 
					             {label:"任务名称", name : 'taskName',sortable:false,width : 200,align : "center"}, 
					             {label:"业务编号", name : 'busId',sortable:false,width : 150,align : "center"}, 
					             {label:"业务名称", name : 'busName',sortable:false,width : 150,align : "center"}, 
					             {label:"流程发起人", name : 'startUserName',sortable:false,width : 130,align : "center"} ,
					             {label:"流程发起人ID", name : 'startUserId',sortable:false,width : 130,align : "center"} ,
					             {label:"任务创建时间", name : 'createTime',sortable:false,width : 140,align : "center",formatter:DatFormatter},
					             {label:"等待处理人", name : 'dealName',sortable:false,width : 150,align : "center"} 
					             ],
		            shrinkToFit:false,   
		            autoScroll: true, 
					rowNum : 10,//一页显示多少条
					rowList : [ 10, 20, 30 ],//可供用户选择一页显示多少条
					rownumWidth: 20, //设置显示序号的宽度，默认为25  
					pager : '#mainGridPager',//表格页脚的占位符(一般是div)的id
					sortname : 'index_Sort',//初始化的时候排序的字段
					sortorder : "asc",//排序方式,可选desc,asc
					mtype : "post",//向后台请求数据的ajax的类型。可选post,get
					width:page.window.grid.width,
					height:page.window.grid.height
				});
		/*创建jqGrid的操作按钮容器*/
		/*可以控制界面上增删改查的按钮是否显示*/
		$("#mainGrid").jqGrid('navGrid', '#mainGridPager', {edit:false,add:false,del:false,search:false,view:false,refresh:false});
	},
	buttonBind:function(){//控制按钮初始化
	  var _this = this;
	  $("#toDoBtn").bind("click",function(){_this.event.doToDo(_this,this)});
	  $("#taskPicBtn").bind("click",function(){_this.event.doPic(_this,this)});
	  $("#applyInfoBtn").bind("click",function(){_this.event.doApply(_this,this)});
	  $("#goBtn").bind("click",function(){_this.event.doGo(_this,this)});//转办
	},
	event:{//事件
		doToDo:function(_this,btn){
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = node;
			  params.menuId = menuId;
			  /*var urlparams = "";
			  for(var p in params){
				  urlparams+="&"+p+"="+params[p];
			  }
			 */
			  showWindow("办理",contextPath+"/act/deal/toDoView.htm",params,function(){
				  GirdCtr.reLoad();
			  },true);
		  }else{
			  layer.msg("选择需要办理的的数据");
		  }
			 
	  },doPic:function(_this,btn){//流程图
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			 var params = {menuId:menuId,processInstanceId:node.InstanceId}
			 var url = contextPath+"/act/deal/flowImgView.htm?processInstanceId="+node.instanceId;
			  var html ="<img src ='"+url+"'/>";
		        //弹框层
		        layer.open({
		            type: 1,
		            area: ['70%', '70%'], //宽高
		            content: html,
		            title:['查看流程图',true],
		            shadeClose: true, //开启遮罩关闭
		        });
		  }else{
			  layer.msg("选择需要查看的数据");
		  }
	  },
	  doApply:function(_this,btn){
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = node;
			  params.menuId = menuId;
			  showWindow("审批记录",contextPath+"/act/common/applyView.htm",params,function(){
				 
			  },true);
		  }else{
			  layer.msg("选择需要查看的的数据");
		  }
	  },
	  doGo:function(_this,btn){//转办
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = node;
			  params.menuId = menuId;
			  showWindow("转办",contextPath+"/act/deal/toTurnView.htm",params,function(){
				  GirdCtr.reLoad();
			  },false);
		  }else{
			  layer.msg("选择需要办理的的数据");
		  }
	  }
	}
});

